using System;
using System.Web.Security;
using System.Security.Principal;
using System.Web.Script.Serialization;

namespace Web.Bid.Extension
{
    public static class IdentityExtension
    {
        private static readonly  JavaScriptSerializer Serializer = new JavaScriptSerializer();
        public static SilenthinkIdentity SkIdentity(this IIdentity identity)
        {
            var id = identity as FormsIdentity;
            if (id != null)
            {
                var data = id.Ticket.UserData;
                try
                {
                    return Serializer.Deserialize<SilenthinkIdentity>(data);
                }
                catch (Exception)
                {
                    return new SilenthinkIdentity(0,string.Empty, string.Empty, string.Empty);
                }
            }
            return new SilenthinkIdentity(0, string.Empty, string.Empty, string.Empty);
        }
    }
}